<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-refresh-right" size="mini" @click="getList">刷新</el-button>
      </el-col>

    </el-row>



    <el-table v-loading="loading" :data="list">

      <el-table-column label="货代公司" align="center" prop="Name" />
      <el-table-column label="公司代码" align="center" prop="Code" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-delete" @click="changeItem(scope.row)">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="goToFee(scope.row, 'Output')">查看出库信息
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="goToFee(scope.row, 'Input')">查看入库信息
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>


    <!-- 添加或修改推荐re对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form :model="form" label-width="80px">

        <el-form-item label="货代公司">
          <el-input v-model="form.Name" placeholder="货代公司" />
        </el-form-item>

        <el-form-item label="公司代码">
          <el-input v-model="form.Code" placeholder="公司代码" />
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>

    </el-dialog>

    <el-dialog title="入库信息" :visible.sync="openInput" width="800px" append-to-body>
      <InputVue :list="openList" v-if="openInput"></InputVue>
    </el-dialog>
    <el-dialog title="出库信息" :visible.sync="openoutput" width="800px" append-to-body>
      <OutputVue :list="openList" v-if="openoutput" />
    </el-dialog>
  </div>
</template>

<script setup>
import { delCompany, upCompany, getCompany, addCompany } from '@/api/company.js';
import { OutputList } from '@/api/portMange';
import FeeVisualVue from '@/components/page/com/FeeVisual.vue';
import InputVue from '../components/Input.vue';
import OutputVue from '../components/Output.vue';
import { DateToStr } from "@/utils/dateUtils"
import {
  inputList
} from '@/api/portMange';

import { ref, reactive } from 'vue'
let openInput = ref(false)
let openoutput = ref(false)
let openList = reactive([])
let rowData = reactive({})
let list = reactive([])
// 遮罩层
let loading = ref(true)
let openFee = ref(false)
// 弹出层标题
let title = ref("")
// 是否显示弹出层
let open = ref(false)
// 表单参数
let form = reactive({})


function getList() {
  loading = true;
  getCompany({}).then(res => {
    list = res.data.value
    loading = false;
  })
};
//获取列表
getList();


function goToFee(row, name) {
  openList = [];
  if (name == "Input") {
    openInput = true;
    inputList({}).then(res => {
      openList = openList.concat(res.data.value.filter(item => item.CompanyId == row.Id))
    })
  } else {
    openoutput = true;
    OutputList({}).then(res => {
      console.log(res.data.value, "hhh");
      openList = openList.concat(res.data.value.filter(item => item.CompanyId == row.Id))
    })
  }

}
// 修改
function changeItem(row) {
  open = true;
  form = row;
};

// 取消按钮
function cancel() {
  open = false;

};


/** 新增按钮操作 */
function handleAdd() {
  form = {}
  open = true;
  title = "添加";
}

/** 提交按钮 */
function submitForm() {
  // form.InputTime = DateToStr(inputDate)
  if (form.Id) {
    upCompany(form).then(res => {
      cancel()
      getList();

    })
  } else {
    addCompany(form).then(res => {
      cancel()
      getList();
    })
  }

}
/** 删除按钮操作 */
function handleDelete(row) {
  let that = this;
  that.$confirm('确定删除?', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    delCompany({
      ids: row.Id
    }).then(res => {
      that.getList();
    })
  }).catch(() => { })
}

</script>
